#
# Copyright 2021 The Modelbox Project Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


cmake_minimum_required(VERSION 3.10)

set(DEVICE_NAME "mockdevice")
project(modelbox-device-${DEVICE_NAME})

file(GLOB_RECURSE LIBMODELBOX_DEVICE_SOURCES *.cpp *.cc *.c)
set(LIBMODELBOX_DEVICE_MOCKDEVICE_INCLUDE ${CMAKE_CURRENT_LIST_DIR}/include)

include_directories(${CMAKE_CURRENT_LIST_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${LIBMODELBOX_INCLUDE})
include_directories(${LIBMODELBOX_BASE_INCLUDE})
include_directories(${LIBMODELBOX_DEVICE_MOCKDEVICE_INCLUDE})
include_directories(${LIBMODELBOX_DEVICE_CPU_INCLUDE})
include_directories(${HUAWEI_SECURE_C_INCLUDE_DIR})

set(LIBMODELBOX_DEVICE_MOCKDEVICE_INCLUDE ${LIBMODELBOX_DEVICE_CPU_INCLUDE} ${LIBMODELBOX_DEVICE_MOCKDEVICE_INCLUDE})
set(LIBMODELBOX_DEVICE_MOCKDEVICE_INCLUDE ${HUAWEI_SECURE_C_INCLUDE_DIR} ${LIBMODELBOX_DEVICE_MOCKDEVICE_INCLUDE})

set(HEADER 
    ${LIBMODELBOX_DEVICE_MOCKDEVICE_INCLUDE}/modelbox
)

set(LIBMODELBOX_DEVICE_MOCKDEVICE_STATIC libmodelbox-device-${DEVICE_NAME}-static)
set(LIBMODELBOX_DEVICE_MOCKDEVICE_SHARED libmodelbox-device-${DEVICE_NAME}-shared)

add_library(${LIBMODELBOX_DEVICE_MOCKDEVICE_STATIC} STATIC ${LIBMODELBOX_DEVICE_SOURCES})
add_library(${LIBMODELBOX_DEVICE_MOCKDEVICE_SHARED} SHARED ${LIBMODELBOX_DEVICE_SOURCES})

set_target_properties(${LIBMODELBOX_DEVICE_MOCKDEVICE_SHARED} PROPERTIES 
    SOVERSION ${MODELBOX_VERSION_MAJOR}
    VERSION ${MODELBOX_VERSION_MAJOR}.${MODELBOX_VERSION_MINOR}.${MODELBOX_VERSION_PATCH}
)

target_link_libraries(${LIBMODELBOX_DEVICE_MOCKDEVICE_STATIC} pthread)
target_link_libraries(${LIBMODELBOX_DEVICE_MOCKDEVICE_STATIC} rt)
target_link_libraries(${LIBMODELBOX_DEVICE_MOCKDEVICE_STATIC} dl)

target_link_libraries(${LIBMODELBOX_DEVICE_MOCKDEVICE_SHARED} ${LIBMODELBOX_SHARED})
target_link_libraries(${LIBMODELBOX_DEVICE_MOCKDEVICE_SHARED} ${LIBMODELBOX_DEVICE_CPU_SHARED})
target_link_libraries(${LIBMODELBOX_DEVICE_MOCKDEVICE_SHARED} ${HUAWEI_SECURE_C_LIBRARIES})
target_link_libraries(${LIBMODELBOX_DEVICE_MOCKDEVICE_SHARED} rt)
target_link_libraries(${LIBMODELBOX_DEVICE_MOCKDEVICE_SHARED} dl)

set_target_properties(${LIBMODELBOX_DEVICE_MOCKDEVICE_STATIC} ${LIBMODELBOX_DEVICE_MOCKDEVICE_SHARED} 
    PROPERTIES OUTPUT_NAME "modelbox-device-${DEVICE_NAME}"
)

configure_file(${CMAKE_CURRENT_LIST_DIR}/libmodelbox-device-${DEVICE_NAME}.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libmodelbox-device-${DEVICE_NAME}.pc @ONLY)

install(TARGETS ${LIBMODELBOX_DEVICE_MOCKDEVICE_SHARED} ${LIBMODELBOX_DEVICE_MOCKDEVICE_STATIC} 
        RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}
        LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}
        ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}
        OPTIONAL)
install(DIRECTORY ${HEADER} DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libmodelbox-device-${DEVICE_NAME}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)

set(LIBMODELBOX_DEVICE_MOCKDEVICE_STATIC ${LIBMODELBOX_DEVICE_MOCKDEVICE_STATIC} CACHE INTERNAL "")
set(LIBMODELBOX_DEVICE_MOCKDEVICE_SHARED ${LIBMODELBOX_DEVICE_MOCKDEVICE_SHARED} CACHE INTERNAL "")
set(LIBMODELBOX_DEVICE_MOCKDEVICE_INCLUDE ${LIBMODELBOX_DEVICE_MOCKDEVICE_INCLUDE} CACHE INTERNAL "")
set(LIBMODELBOX_DEVICE_SOURCES ${LIBMODELBOX_DEVICE_SOURCES} CACHE INTERNAL "")
set(LIBMODELBOX_DEVICE_MOCKDEVICE_SO ${CMAKE_CURRENT_BINARY_DIR}/libmodelbox-device-${DEVICE_NAME}.so CACHE INTERNAL "")

